package com.rx.mgt.dao;

import com.rx.mgt.dao.base.ManagementHibernateDaoBase;
import com.rx.mgt.domain.GroupManager;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by zxj on 2017/4/27.
 */
@Repository
public class GroupMangerDao extends ManagementHibernateDaoBase<GroupManager,Long> {


    public List<GroupManager> queryGroupMangerList(String domain) {
        String hql  = " select new GroupManager(gm.id,gm.email,gm.password,gm.groupId,gm.ipAddess,gm.ipAddess,g.name) from GroupManager gm,Group g where 1=1 and gm.groupId=g.id";
        if(StringUtils.isNotBlank(domain)){
            hql +=" and gm.domain=:domain";
        }

        Query query = template.getSessionFactory().getCurrentSession().createQuery(hql);
        if(StringUtils.isNotBlank(domain)){
            query.setParameter("domain",domain);
        }
        return query.list();

    }
}
